﻿using System;
//using QIMSServer.Service;
using System.Resources;
using System.Collections;

namespace MaxStudio.Concrete.DBUtility
{
    public class DlHelper
    {
        /// <summary>
        /// Format Recod Exception, return string
        /// 记录Exception到SystemLog中
        /// </summary>
        /// <param name="ex">Exception</param>
        /// <returns></returns>
        public static string ExceptionString(Exception ex)
        {
           // SystemLog.logError(ex);
            return ex.Message;// +"<br/>" + ex.StackTrace;
        }

        public static string StatusSting(bool value)
        {
            //string keyValue = "", keyValue2 = "";
            //IResourceReader reader = new ResourceReader("Resources.QIMSFieldName");
            //IDictionaryEnumerator en = reader.GetEnumerator();
            //Type type = typeof(IDictionaryEnumerator);
            //System.Reflection.PropertyInfo property = type.GetProperty("Common_Status_Active");
            //if (property != null)
            //    keyValue = property.ToString();
            //property = type.GetProperty("Common_Status_Inactive");
            //if (property != null)
            //    keyValue2 = property.ToString();

            //return value ? keyValue : keyValue2;
            return value ? StatusEnum.active.ToString() : StatusEnum.inactive.ToString();
        }

        public static string FormatNumberString(decimal value)
        {
            //value.ToString("d");
            return "";// QIMSServer.Dao.QIMSExtentions.ToCustomString(value);
        }

        public static DateTime getCurrentDate()
        {
            DateTime dt = QIMSUtility.getCurrentDateTime();
            dt = new DateTime(dt.Year, dt.Month, dt.Day, 0, 0, 0);
            return dt;
        }

        public static void SetRowColumnFromCellString(string cellString, out int row, out int column)
        {
            row = 0;
            column = 0;
            try
            {
                string colString = cellString.Split(',')[0];
                string rowString = cellString.Split(',')[1];
                for (int i = 0; i < colString.Length; i++)
                {
                    char c = colString[i];
                    if (c >= 'A' && c <= 'Z')
                    {
                        column += (c - 64) * (int)Math.Pow(26, colString.Length - i - 1);
                    }
                    else if (c >= 'a' && c <= 'z')
                    {
                        column += (c - 96) * (int)Math.Pow(26, colString.Length - i - 1);
                    }
                    else
                    {
                        throw new Exception();
                    }
                }
                row = int.Parse(rowString);
            }
            catch
            {
                row = -1;
                column = -1;
            }
        }
    }
}
